package com.sh.studytwo;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class ButtonClickActivity extends AppCompatActivity implements View.OnClickListener{

    private TextView btnRes;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_button_click);
        Button btn = findViewById(R.id.btn_click_single);
        btnRes = findViewById(R.id.tv_result_single);
        btn.setOnClickListener(new MyViewOnClickListener(btnRes));
        Button btn_public = findViewById(R.id.btn_click_public);
        btn_public.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_click_public) {
            btnRes.setText("这是公共监听的点击事件");
        }
    }


    static class MyViewOnClickListener implements View.OnClickListener {

        private TextView textView;

        public MyViewOnClickListener(TextView textView) {
            this.textView = textView;
        }

        @Override
        public void onClick(View v) {
            textView.setText("新的结果");
        }
    }
}